//app.js
App({
  //第一次进来会触发，关闭小程序后再进来不会触发，关闭微信再进来会触发,删除小程序再进来就会执行 
  //setStorage 在关闭微信后进来还是会存在，但是删除小程序就会被删除
  //app.globalData 关闭微信的时候就不存在了，删除小程序的时候也肯定不在
  onLaunch: function () {
    var that=this;
    wx.getSystemInfo({
      success:function(res){
        that.globalData.systemInfo=res;
        that.globalData.version = res.version;
        that.globalData.deviceName=res.model;
      }
    })
  },
  logout:function(){
    var that=this;
   
      wx.clearStorage({
        success:function(res){
          that.globalData.userInfo = "";
          that.globalData.okey = "";
          wx.showToast({
            title: '退出成功！',
            icon: 'success',
            duration: 2000,
            success: function () {
                setTimeout(function(){
                  wx.reLaunch({
                    url: '/pages/index/index/index'
                  })
                },1000)
            }
          })
        }
      });
      
  },
  getUkey:function(){
    var ukey;
    if (this.globalData.userInfo){
      ukey = this.globalData.userInfo.ukey;
    }else{
      ukey = wx.getStorageSync('userinfo').ukey;//同步获取
    }
    return ukey  ? ukey :"";
  },
  getStoreUserInfo: function () {
    var userInfo;
    if (this.globalData.userInfo) {
      userInfo = this.globalData.userInfo;
    } else {
      userInfo = wx.getStorageSync('userinfo');//同步获取
    }
    return userInfo ? userInfo : false;
  },

  getFormIds: function (formId){
    let formIds = this.globalData.formIds;
    if (!formIds){
      formIds = [];
    }
    if (formId != "the formId is a mock one"){
      let data = {
        id: formId,
        expire: new Date().getTime() + 604800000 // 7天后的过期时间戳
      }
      formIds.push(data);// 将data添加到数组的末尾
      this.globalData.formIds = formIds;// 保存推送码并赋值给全局变量
    }
    
    
  },
  globalData: {
    systemInfo:"",
    deviceName:"",
    version:"",
    okey:"",
    userInfo:"",
    formIds:""
  }
})